<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // let arr =[1,2,3,4]
      // let it =arr[Symbol.iterator]()
      // console.log(it.next());
      // console.log(it.next());
      // console.log(it.next());
      // console.log(it.next());
      // console.log(it.next());

      function* foo(params) {
        yield 5;
        yield 6;
        yield 7;
      }
      var yi = foo();
      console.log(yi);
      console.log(yi.next());
      console.log(yi.next());
      console.log(yi.next());
      console.log(yi.next());

      // function myFoo() {
      //     let res =asyncMethod(5)
      //     console.log(res);
      // }

      // function asyncMethod(x) {
      //     setTimeout(() => {
      //         return x*x
      //     }, 1000);
      // }

      function* myFoo() {
        var res = yield asyncMethod(5);
        console.log(res);
      }

      function asyncMethod(x) {
        setTimeout(() => {
          console.log(x);
          g.next(x * x);
        }, 2000);
      }
      var g = myFoo();
      g.next();
    </script>
  </body>
</html>
